package com.fmc.passport.util;

import java.util.Vector;

public class StringUtil {

	public static String nvl(Object obj1, String strReturn) {
		if (obj1 == null) {
			return strReturn;
		} else {
			return obj1.toString();
		}
	}

	public static String currencyFormat(Object obj, String sperator) {

		String str = StringUtil.nvl(obj, "");
		StringBuilder sb = null;
		if (!str.equals("")) {
			if (isNumber(str)) {
				if (str.length() > 3) {
					sb = new StringBuilder(str);
					sb = sb.reverse();
					str = sb.toString();
					int numLoop = str.length() / 3;

					for (int i = 0; i < numLoop; i++) {
						str = str.substring(0, (i + 1) * 3 + i) + sperator
								+ str.substring((i + 1) * 3 + i, str.length());
					}
				}
				sb = new StringBuilder(str);
				str = sb.reverse().toString();
				if (str.startsWith(sperator)) {
					str = str.replaceFirst(sperator, "");
				}
			}
		}

		return str;
	}

	/*
	 * private util funtion
	 */
	private static boolean isNumber(String str) {
		try {
			Integer.parseInt(str);
			return true;
		} catch (NumberFormatException ex) {
			return false;
		}
	}

}
